import java.util.Arrays;

/**
 * Created by Yasin H on 2017/7/28.
 */
public class ThreeSumFast {

    public static int count(int[] a) {
        Arrays.sort(a);
        int n = a.length;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (BinarySearch.rank(-a[i] - a[j], a) > j)
                    cnt++;
            }
        }
        return cnt;
    }

}
